// 商品相关接口
import http from "../common/http.js";
import goodsCart from "./goodscart.js";

export default {
  // 获取下单信息展示
  orderInformation: (data, needLoading) => {
    return http.GET("/default/buy-goods-log", data, needLoading);
  },

  //订阅降价提醒
  getPriceDesire: (data, needLoading) => {
    return http.GET("/goods/goods-lowering-price", data, needLoading);
  },
  //取消降价提醒
  cancelPriceDesire: (data, needLoading) => {
    return http.GET("/goods/cancel-goods-lowering-price", data, needLoading);
  },
  //获取商品详情
  goodsDetails: (data, needLoading) => {
    return http.GET("/goods/goods", data, needLoading);
  },
  //获取商品详情页优惠内容
  getGoodYouHui: (data, needLoading) => {
    return http.GET("/goods/get-goods-youhui", data, needLoading);
  },
  //商品详情页记录浏览记录
  browse: (data, needLoading) => {
    return http.GET("/default/browse", data, needLoading);
  },
  //商品详情页中的推荐商品
  goodsRecommend: (data, needLoading) => {
    return http.GET("/goods/goods-recommend", data, needLoading);
  },
  //商品详情页中评论获取
  commentList: (data, needLoading) => {
    return http.GET("/default/comment-list", data, needLoading);
  },
  //商品详情页中领取优惠券
  couponReceive: (data, needLoading) => {
    return http.GET("/coupon/receive", data, needLoading);
  },
  //商品详情页中收藏该商品
  favoriteGoods: (data, needLoading) => {
    return http.POST("/user/favorite-add", data, needLoading);
  },
  //商品详情页中取消收藏该商品
  favoriteRemove: (data, needLoading) => {
    return http.POST("/user/favorite-remove", data, needLoading);
  },
  //通过选取规格获取该规格下的商品准确价格
  goodsAttrInfo: (data, needLoading) => {
    return http.GET("/default/goods-attr-info", data, needLoading);
  },
  //添加商品到购物车
  addCart: async (data, needLoading) => {
    const res = await http.POST("/cart/add-cart", data, needLoading);
    goodsCart.getCartList();
    return res;
  },
  //删除商品
  cartReduce: (data, needLoading) => {
    return http.GET("/cart/cart-reduce", data, needLoading);
  },
  //商品海报
  goodsQrcode: (data, needLoading) => {
    return http.GET("/default/goods-qrcode", data, true);
  },
  //获取收货地址信息
  getAddressInfo: (data, needLoading) => {
    return http.GET("/goods/address", data, needLoading);
  },
  //获取店铺推荐商品列表
  getShopRecommend: (data, needLoading) => {
    return http.GET("/goods/mch-recommend", data, needLoading);
  },
  //获取店铺推荐商品列表
  getLikeGoods: (data, needLoading) => {
    return http.GET("/goods/guess-like", data, needLoading);
  },
  updateGoodsSku(data, needLoading) {
    return http.POST("/cart/update-cart", data, needLoading);
  },
  // 通过md_id获取门店数据
  getMdAddress: (data) => {
    return http.GET("/goods/md-address", data);
  },

  //获取商品详情
  goodsDetails: (data, needLoading) => {
    return http.GET("/goods/goods", data, needLoading);
  },
  //获取商品详情页优惠内容
  getGoodYouHui: (data, needLoading) => {
    return http.GET("/goods/get-goods-youhui", data, needLoading);
  },
  //商品详情页记录浏览记录
  browse: (data, needLoading) => {
    return http.GET("/default/browse", data, needLoading);
  },
  //商品详情页中的推荐商品
  goodsRecommend: (data, needLoading) => {
    return http.GET("/goods/goods-recommend", data, needLoading);
  },
  //商品详情页中评论获取
  commentList: (data, needLoading) => {
    return http.GET("/default/comment-list", data, needLoading);
  },
  //商品详情页中领取优惠券
  couponReceive: (data, needLoading) => {
    return http.GET("/coupon/receive", data, needLoading);
  },
  //商品详情页中收藏该商品
  favoriteGoods: (data, needLoading) => {
    return http.POST("/user/favorite-add", data, needLoading);
  },
  //商品详情页中取消收藏该商品
  favoriteRemove: (data, needLoading) => {
    return http.POST("/user/favorite-remove", data, needLoading);
  },
  //通过选取规格获取该规格下的商品准确价格
  goodsAttrInfo: (data, needLoading) => {
    return http.GET("/default/goods-attr-info", data, needLoading);
  },
  //添加商品到购物车
  addCart: async (data, needLoading) => {
    const res = await http.POST("/cart/add-cart", data, needLoading);
    goodsCart.getCartList();
    return res;
  },
  //删除商品
  cartReduce: (data, needLoading) => {
    return http.GET("/cart/cart-reduce", data, needLoading);
  },
  //商品海报
  goodsQrcode: (data, needLoading) => {
    return http.GET("/default/goods-qrcode", data, true);
  },
  //获取收货地址信息
  getAddressInfo: (data, needLoading) => {
    return http.GET("/goods/address", data, needLoading);
  },
  //获取店铺推荐商品列表
  getShopRecommend: (data, needLoading) => {
    return http.GET("/goods/mch-recommend", data, needLoading);
  },
  //获取店铺推荐商品列表
  getLikeGoods: (data, needLoading) => {
    return http.GET("/goods/guess-like", data, needLoading);
  },
  updateGoodsSku(data, needLoading) {
    return http.POST("/cart/update-cart", data, needLoading);
  },
  // 通过md_id获取门店数据
  getMdAddress: (data) => {
    return http.GET("/goods/md-address", data);
  },
  //（拼团）通过选取规格获取该规格下的商品准确价格
  ptGoodsAttrInfo: (data, needLoading) => {
    return http.GET("/default/goods-attr-info", data, needLoading);
  },

  formInfo: (data, needLoading) => {
    return http.GET("/form/form-info", data, needLoading);
  },
  formDataSave: (data, needLoading) => {
    return http.POSTJSON("/form/form-data-save", data, needLoading);
  },
  formDataList: (data, needLoading) => {
    return http.GET("/form/form-data-list", data, needLoading);
  },
  formDataInfo: (data, needLoading) => {
    return http.GET("/form/form-data-info", data, needLoading);
  },
  getBrandList: (data, needLoading) => {
    return http.GET("/goods-brand/get-brand-list", data, needLoading);
  },
};
